public class Woodcutting {
	private client c = null;
	public double expRate;
	public boolean isWoodcutting;
	public int treeId;
	public int emoteId;
	public int expAmount;
	public long wcDelay;
	public int[] birdNest = {5070, 5071, 5072, 5073, 5074, 5075};
	public int[] hatchetIds = {1351, 1349, 1353, 1361, 1355, 1357, 1359, 6739};
	 
	public Woodcutting(client client) {
		this.c = client;
		this.isWoodcutting = false;
		this.treeId = -1;
		this.emoteId = 0x284;
		this.expRate = 1.0;
		this.wcDelay = -1;
	}
	 
	public client getClient() {
		return c;
	}
	
	public int getHatchetReq() {
		switch (getHatchetId()) {
		case 1351:
		case 1349:
			return 1;
		case 1353:
			return 7;
		case 1361:
			return 15;
		case 1355:
			return 21;
		case 1357:
			return 31;
		case 1359:
			return 41;
		case 6739:
			return 61;
		default:
			return 1;
		}
	}
	
	public int getHatchetId() {
		for (int i = 0; i < hatchetIds.length; i++) {
			if (getClient().playerEquipment[getClient().playerWeapon] == hatchetIds[i] || getClient().playerHasItem(hatchetIds[i])) {
				return hatchetIds[i];
			}
		}
		return -1;
	}
	
	public void sM(final int msgIndex) {
		switch (msgIndex) {
		case 0:
			getClient().sM("You need a hatchet to chop down this tree.");
			getClient().sM("You do not have a hatchet which you have the Woodcutting level to use.");
			break;
		case 1:
			getClient().sM("You've just advanced a Woodcutting level! You have reached level " + getWoodcuttingLevel() + ".");
			break;
		case 2:
			getClient().sM("You swing your axe at the tree.");
			break;
		case 3:
			getClient().sM("A bird's nest falls out of the tree.");
			break;
		case 4:
			getClient().sM("Your inventory is too full to hold any more logs.");
			break;
		default:
			getClient().sM("Woodcutting - exception in method: sM(int)");
			break;
		}
	}
	
	public int getWoodcuttingLevel() {
		return getClient().playerLevel[getClient().playerWoodcutting];
	}
	
	public int getLogId() {
		switch (treeId) {
		case 1281:
			return 1521;
		case 1308:
		case 5551:
		case 5552:
		case 5553:
			return 1519;
		case 1307:
		case 4674:
			return 1517;
		case 1309:
			return 1515;
		case 1306:
			return 1513;
		default: // Normal trees + missing.
			return 1511;
		}
	}
	
	public void reset() {
		this.isWoodcutting = false;
		this.treeId = -1;
		this.emoteId = 0x284;
		this.wcDelay = -1;
	}
	
	public void giveNest() {
		try {
			int nestId = birdNest[misc.random(birdNest.length)];
			ItemHandler.addItem(nestId, (getClient().absX + 1), (getClient().absY - 1), 1, getClient().playerId, false);
			sM(3);
		} catch (Exception e) {
			giveNest();
		}
	}
	
	public boolean objectIsTree(int objectId) {
		switch (objectId) {
		case 1276:
		case 1277:
		case 1278:
		case 1279:
		case 1280:
		case 1315:
		case 1316:
		case 1281:
		case 1308:
		case 5551:
		case 5552:
		case 5553:
		case 1307:
		case 4674:
		case 1309:
		case 1306:
			return true;
		default:
			return false;
		}
	}
	
	public double getExp() {
		switch (treeId) {
		case 1281:
			return 30;
		case 1308:
		case 5551:
		case 5552:
		case 5553:
			return 50;
		case 1307:
		case 4674:
			return 80;
		case 1309:
			return 130;
		case 1306:
			return 1000;
		default:
			return 25;
		}
	}
	
	public int getReq() {
		switch (treeId) {
		case 1281:
			return 15;
		case 1308:
		case 5551:
		case 5552:
		case 5553:
			return 30;
		case 1307:
		case 4674:
			return 45;
		case 1309:
			return 60;
		case 1306:
			return 75;
		default: // Normal tree's + missing
			return 1;
		}
	}
	
	public void startWc(int treeId) {
		this.treeId = treeId;
		if (getReq() > getWoodcuttingLevel()) {
			getClient().sM("You need a Woodcutting level of " + getReq() + " to chop down this tree.");
			return;
		}
		if (getHatchetId() == -1 || (getHatchetReq() > getWoodcuttingLevel())) {
			sM(0);
			return;
		}
		if (getClient().freeSlots() == 0) {
			sM(4);
			return;
		}
		if (!wieldHatchet()) {
			int hatchetId = getHatchetId();
			getClient().deleteItem(hatchetId, 1);
			getClient().addItem(getClient().playerEquipment[getClient().playerWeapon], 1);
			getClient().playerEquipment[getClient().playerWeapon] = hatchetId;
			getClient().playerEquipmentN[getClient().playerWeapon] = 1;
			getClient().setEquipment(getClient().playerEquipment[getClient().playerWeapon], getClient().playerEquipmentN[getClient().playerWeapon], getClient().playerWeapon);
		}
		getClient().pEmote = this.emoteId;
		this.isWoodcutting = true;
		this.emoteId = 0x284;
		this.wcDelay = System.currentTimeMillis();
		sM(2);
	}
	
	public long getTreeDelay() {
		switch (treeId) {
		case 1281:
			return 2800;
		case 1308:
		case 5551:
		case 5552:
		case 5553:
			return 3000;
		case 1307:
		case 4674:
			return 3250;
		case 1309:
			return 6500;
		case 1306:
			return 7500;
		default: // Normal trees + missing trees.
			return 2300;
		}
	}
	
	public boolean wieldHatchet() {
		switch (getClient().playerEquipment[getClient().playerWeapon]) {
		case 1351:
		case 1349:
		case 1353:
		case 1361:
		case 1355:
		case 1357:
		case 1359:
		case 6739:
			return true;
		default:
			return false;
		}
	}
	
	public void wcProcess() {
		if (misc.random2(500) >= 499)
			giveNest();
		if (getHatchetId() == -1 || (getHatchetReq() > getWoodcuttingLevel()))
			return;
		if (((System.currentTimeMillis() - wcDelay) >= getTreeDelay()) && (isWoodcutting)) {
			int currentLevel = getWoodcuttingLevel();
			getClient().addItem(getLogId(), 1);
			getClient().sM("You get some " + getClient().getItemName(getLogId()).toLowerCase() + ".");
			getClient().addSkillXP((int) Math.floor(getExp() * expRate), getClient().playerWoodcutting);
			if (currentLevel < getWoodcuttingLevel()) sM(1);
			getClient().pEmote = this.emoteId;
			getClient().savegame(true);
			this.wcDelay = System.currentTimeMillis();
			if (getClient().freeSlots() == 0) {
				sM(4);
				reset();
				getClient().resetAnimation();
				return;
			}
		}
	}
}